import axios from 'axios'
import { Message, MessageBox } from 'element-ui'

// 创建axios实例
const service = axios.create({
    // baseURL: process.env.BASE_API, // api的base_url
    timeout: 15000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(config => {
  let url = config.url;
  if (url === 'webApi/web/login') {
    return config;
  }
  config.headers['Authorization'] = localStorage.getItem("web-token");
  return config
}, error => {
  console.log(error)
  Promise.reject(error)
})


// response拦截器
service.interceptors.response.use(
    response => {
        return response
    },
    error => {
      let data = error.response.data;
      let msg = data.message;
      Message({
        message: msg,
        type: 'error',
        duration: 3 * 1000
      })
      return Promise.reject(error)
    }
)
  
export default service